package edu.scau.mis.pos.controller;


import edu.scau.mis.pos.entity.PosItem;
import edu.scau.mis.pos.entity.PosOrder;
import edu.scau.mis.pos.entity.PosOrderItem;
import edu.scau.mis.pos.service.IOrderItemService;
import edu.scau.mis.pos.vo.DashboardVo;
import edu.scau.mis.pos.vo.OrderItemVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * (PosOrderItem)表控制层
 *
 * @author makejava
 * @since 2021-11-04 23:21:21
 */
@RestController
@RequestMapping("pos_order_item")
@ResponseBody
public class OrderItemController {
    @Autowired
    private IOrderItemService orderItemService;
    /**
     * 步骤1:查询读者及业务信息
     *
     * @param orderNo 读者证号
     * @return 读者、借书数量、超期图书数量信息
     */
    @GetMapping("/getOrderInfo")
    public ResponseEntity<Map<String,Object>> getOrderInfo(@RequestParam("orderNo") String orderNo) {
        return ResponseEntity.ok(this.orderItemService.getOrderAndBuyInformationByOrderNo(orderNo));
    }

    /**
     * 步骤2:输入待借读者-图书
     *
     * @param orderItemVo 传值对象
     * @return 新增结果
     */
    @GetMapping ("/enterItem")
    public List<PosItem> enterItem(OrderItemVo orderItemVo) {
        return this.orderItemService.enterLineOrderItem(orderItemVo);
    }

    /**
     * Echarts饼状图数据接口
     * @return
     */
    @GetMapping("/pie")
    public ResponseEntity<List<DashboardVo>> pie(){
        return ResponseEntity.ok(this.orderItemService.CountByCategoryId());
    }

    /**
     * 确认借书
     * 步骤3
     * @param orderNo 读者证号
     * @return 新增结果
     */

    @GetMapping("/confirmBuy")
    public ResponseEntity<Boolean> confirmBuy(@RequestParam("orderNo") String orderNo) {

        return ResponseEntity.ok(this.orderItemService.ConfirmBuyItem(orderNo));

    }


    @GetMapping("/list")
    @ApiOperation("查询产品列表")
    public List<PosOrderItem> queryAll(@RequestBody PosOrderItem posOrderItem) {
        return orderItemService.queryAll(posOrderItem);

    }
}

